function setSync(event)
{
  var prefService = Components.classes["@mozilla.org/preferences-service;1"]
                              .getService(Components.interfaces.nsIPrefService);
  var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]  
                          .getService(Components.interfaces.nsIPromptService);  
   
  var accountName = "feeds"; //TODO: figure out feeds.
  var folder = GetFirstSelectedMsgFolder();
  
  if(folder.server.type == "nntp") {
    accountName = folder.name;
    var prefName = "mailnews.sync.account." + folder.server.type + "." + accountName;
    var accountsToSync = prefService.getCharPref("mailnews.sync.accounts.fullupload");
    
    if (event.getAttribute("checked") == "true") {
      accountsToSync = accountsToSync + "" + accountName + ",";
      prefService.setCharPref("mailnews.sync.accounts.fullupload", accountsToSync);
      prefService.setBoolPref(prefName, true);
      prompts.alert(null, "Sync MailNews Headers", "Sync enabled for: " + accountName);
    } else {
        prefService.setBoolPref(prefName, false);
        var arr = accountsToSync.split(",");
        var arrStringified = "";
        for (var i = 0; i < (arr.length - 1); i++) {
    	  if ( arr[i] != accountName )
    	    arrStringified += arr[i] + ",";
        }
        prefService.setCharPref("mailnews.sync.accounts.fullupload", arrStringified);
        prompts.alert(null, "Sync MailNews Headers", "Sync disabled for: " + accountName);
    }
  }
}

function setSyncMenuItem(event)
{
  try {
    var checkbox = document.getElementById("syncBox");
    var folder = GetFirstSelectedMsgFolder();

    if (folder.server.type == "nntp") {
      checkbox.setAttribute("disabled",false);
      var property = false;
      checkbox.setAttribute("checked",property);
      var prefService = Components.classes["@mozilla.org/preferences-service;1"]
                                  .getService(Components.interfaces.nsIPrefService);
      var prefName = "mailnews.sync.account.nntp." + folder.name;
    
      property = prefService.getBoolPref(prefName);
      checkbox.setAttribute("checked",property);
      checkbox.setAttribute("style","display:block");
    } else if (folder.server.type == "rss") {
        checkbox.setAttribute("checked",true);
        checkbox.setAttribute("disabled",true);
        checkbox.setAttribute("style","display:block");
    } else {
        checkbox.setAttribute("style","display:none");
    }

  }
  catch (e) {
    dump(e.toString());
  }
}
